<!--普通页面的头部部分-->
<template>
  <header class="normal-header">
    <div class="header-back" @click="goBack" v-if="showLeft"></div>
    <span class="header-title font-32">{{ title }}</span>
    <div class="header-search" @click="goSearch" v-if="showRight"></div>
  </header>
</template>

<script>
export default {
  name: 'NormalHeader',

  props: {
    title: {
      type: String,
      default: '漫画岛'
    },

    // 为了方便后面组件直接用该组件，该组件头部有三部分，左中右，后面的组件有的只用了左和中，
    // 有的组件用了右边和中间
    showLeft: {
      type: Boolean,
      default: true
    },

    showRight: {
      type: Boolean,
      default: true
    }
  },

  methods: {
    goBack() {
      // 使用编程式导航,返回上一页
      this.$router.back()
    },

    goSearch() {
      this.$router.push('/search')
    }
  }
}
</script>
<style lang="less" scoped>
.normal-header {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 44px;
  box-sizing: border-box;
  background-color: #fff;
  position: relative;
  &::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1px;
    background: #e9e9e9;
    transform: scaleY(0.5);
  }
  .header-back {
    position: absolute;
    top: 50%;
    left: 12px;
    margin-top: -7px;
    width: 24px;
    height: 14px;
    background: url("~@/assets/icon/header-back.png") no-repeat;
    background-size: 100%;
  }
  .header-title {
    max-width: 70%;
    color: #333;
    font-weight: 500;
    text-align: center;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  .header-search {
    width: 22px;
    height: 22px;
    position: absolute;
    top: 50%;
    right: 12px;
    margin-top: -11px;
    background: url("~@/assets/icon/header-search.png") no-repeat;
    background-size: 100%;
  }
}
</style>
